package com.xiaogao.serviceEdu.controller;


import com.xiaogao.commonUtils.Result;
import com.xiaogao.serviceEdu.entity.vo.SubjectVO;
import com.xiaogao.serviceEdu.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author 小高
 * @since 2021-06-06
 */
@RestController
@RequestMapping("/serviceEdu/subject")
@Api(description="课程分类管理")
public class EduSubjectController {

    @Autowired
    private EduSubjectService subjectService;

    // 添加课程分类
    // 获取上传过来的文件，把文件内容读出来
    @ApiOperation(value = "Excel批量导入")
    @PostMapping("/addSubject")
    public Result addSubject(
            @ApiParam(name = "file",value = "Excel文件",required = true)
            MultipartFile file){

        // 获取上传的excel文件 MultipartFile
        subjectService.saveSubject(file,subjectService);
        return Result.ok();
    }

    @ApiOperation(value = "课程分类列表（树形）")
    @GetMapping("/getSubjects")
    public Result getSubjects(){
        List<SubjectVO> list = subjectService.getAllSubject();
        return Result.ok().data("items",list);
    }

}

